package com.dingwei.superiordiary.ui.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.bean.TipTypeBean;
import com.dingwei.superiordiary.mvp.presenter.ReportPresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.Set;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created time 2018/1/30.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class ReportActivity extends BaseActivity implements Contract.ReportView {

    ReportPresenter reportPresenter = new ReportPresenter(this);
    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.id_flow_layout)
    TagFlowLayout idFlowLayout;
    @Bind(R.id.et_other_content)
    EditText etOtherContent;
    @Bind(R.id.btn_submit)
    Button btnSubmit;
    TipTypeBean bean;

    String type;
    String tip_type;
    @Override
    protected int getContentViewId() {
        return R.layout.activity_report;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        tvTitle.setText("举报");
        tip_type =  getIntent().getStringExtra("tip_type");
        reportPresenter.initType();
    }

    @Override
    protected void initListener() {
        idFlowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int i, FlowLayout flowLayout) {
                type = bean.data.get(i).id+"";
                return false;
            }
        });
        idFlowLayout.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
            @Override
            public void onSelected(Set<Integer> set) {
                if (set.size()==0){
                    type = "";
                }
            }
        });
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.img_back, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.btn_submit:
                reportPresenter.tip(getIntent().getStringExtra("id"),type,etOtherContent.getText().toString().trim(),tip_type);
                break;
        }
    }

    @Override
    public void getData(TipTypeBean bean) {
        this.bean = bean;
        idFlowLayout.setAdapter(new TagAdapter<TipTypeBean.DataBean>(bean.data) {
            @Override
            public View getView(FlowLayout flowLayout, int i, TipTypeBean.DataBean dataBean) {
                TextView tv = (TextView) LayoutInflater.from(context).inflate(R.layout.item_flow_layout,
                        idFlowLayout, false);
                tv.setText(dataBean.label);
                return tv;
            }
        });
    }

    @Override
    public void tipSuccess() {
        finish();
    }
}
